use serde::{Deserialize, Serialize};

// SymbolOrderData 结构体（保持不变）
#[derive(Debug, Serialize)]
pub(crate) struct SymbolOrderData {
    pub id: i64,
    pub symbol: String,
    pub entry_id: String,
    pub price: f64,
    pub order_type: String,
    pub order_side: String,
    pub position: f64,
    pub net_position: f64,
    pub order_id: String,
    pub order_status: String,
    pub create_time: chrono::NaiveDateTime,
}

impl SymbolOrderData {
    pub fn new(
        id: i64,
        symbol: String,
        entry_id: String,
        price: f64,
        order_type: String,
        order_side: String,
        position: f64,
        net_position: f64,
        order_id: String,
        order_status: String,
        create_time: chrono::NaiveDateTime,
    ) -> Self {
        SymbolOrderData {
            id,
            symbol,
            entry_id,
            price,
            order_type,
            order_side,
            position,
            net_position,
            order_id,
            order_status,
            create_time,
        }
    }
}
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct Candlestick {
    pub open_time: u64,
    pub open: f64,
    pub high: f64,
    pub low: f64,
    pub close: f64,
    pub volume: f64,
    pub close_time: u64,
    pub quote_volume: f64,
    pub trade_count: u32,
    pub taker_buy_volume: f64,
    pub taker_buy_quote: f64,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] // Binance uses camelCase in JSON
pub(crate) struct OrderResult {
    pub symbol: String,
    pub order_id: i64,
    pub order_list_id: i64,
    pub client_order_id: String,
    pub transact_time: u64,
    pub price: String,
    pub orig_qty: String,
    pub executed_qty: String,
    pub orig_quote_order_qty: String,
    pub cummulative_quote_qty: String,
    #[serde(rename = "status")]
    pub order_status: String,
    pub time_in_force: String,
    // 转义名称
    #[serde(rename = "type")]
    pub order_type: String,
    pub side: String,
    pub working_time: u64,
    pub self_trade_prevention_mode: String,
}

// 定义订单数据的 Rust 结构体
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] // 处理 JSON 中的 camelCase 字段名
pub(crate) struct FutureOrderResult {
    pub client_order_id: String, // 用户自定义订单号
    pub cum_qty: String,         // 累计成交量
    pub cum_quote: String,       // 成交金额
    pub executed_qty: String,    // 已成交数量
    pub order_id: i64,           // 系统订单号
    pub avg_price: String,       // 平均成交价
    pub orig_qty: String,        // 原始委托数量
    pub price: String,           // 委托价格
    pub reduce_only: bool,       // 是否仅减仓
    pub side: String,            // 买卖方向
    pub position_side: String,
    #[serde(rename = "status")] // 持仓方向
    pub order_status: String, // 订单状态
    pub stop_price: String,    // 触发价
    pub close_position: bool,  // 是否条件全平仓
    pub symbol: String,        // 交易对
    pub time_in_force: String, // 有效方式
    #[serde(rename = "type")]
    pub order_type: String, // 订单类型
    pub orig_type: String,     // 触发前订单类型
    pub activate_price: Option<String>, // 跟踪止损激活价格（可选字段）
    pub price_rate: Option<String>, // 跟踪止损回调比例（可选字段）
    pub update_time: i64,      // 更新时间（毫秒时间戳）
    pub working_type: String,  // 条件价格触发类型
    pub price_protect: bool,   // 是否开启条件单触发保护
    pub price_match: String,   // 盘口价格下单模式
    pub self_trade_prevention_mode: String, // 订单自成交保护模式
    pub good_till_date: i64,   // GTD 订单的自动取消时间（毫秒时间戳）
}
